package edu.umn.se.trap.logicChecker;

import java.util.Observable;
import edu.umn.se.trap.Form;
import edu.umn.se.trap.exceptions.TrapException;

public class LogicChecker extends Observable{
    /**
     * sets an exception to be returned later
     * NOTE that even though many different kinds of exceptions can be thrown,
     * they will all appear as trap exceptions
     */
    private TrapException te = null;

    /**
     * at initialization, we add all of the different checks as observers
     */
    public LogicChecker(){
        this.addObserver(new CheckLogicAirDomestic());
        this.addObserver(new CheckLogicAlcohol());
        this.addObserver(new CheckLogicDODBreakfast());
        this.addObserver(new CheckLogicDODHertz());
        this.addObserver(new CheckLogicDODNoForeignExpense());
        this.addObserver(new CheckLogicForeignGov());
        this.addObserver(new CheckLogicInternet());
        this.addObserver(new CheckLogicNIHFood());
        this.addObserver(new CheckLogicNIHTransit());
        this.addObserver(new CheckLogicNoExportCitizenship());
        this.addObserver(new CheckLogicRentalAgency());
        this.addObserver(new CheckSyntaxDate());
        this.addObserver(new CheckSyntaxDay());
        this.addObserver(new CheckSyntaxGrant());
        this.addObserver(new CheckSyntaxOtherExpense());
        this.addObserver(new CheckSyntaxTransportation());
        this.addObserver(new CheckSyntaxTravelDetails());
    }
    /**
     * Checks the form for business logic and syntax
     * it sets the observable as changed and notifies all of the observers
     * @param form - the form to be checked
     */
    public void checkForm(Form form){
        this.setChanged();
        this.notifyObservers(form);
        
    }
    /**
     * sets an exception to be thrown later
     * @param e - the exception to be thrown later
     */
    public void setException(TrapException e){
        te = e;
    }
    /**
     * gets a saved exception to throw
     * @return - an exception to be thrown or null
     */
    public TrapException getException(){
        return te;
    }

}